package com.xuerhua.yxt.controller.sys;

import java.io.*;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.xuerhua.yxt.common.AdminUser;
import com.xuerhua.yxt.model.*;
import com.xuerhua.yxt.view.*;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.xuerhua.yxt.common.Const;
import com.xuerhua.yxt.common.RspResult;
import com.xuerhua.yxt.common.enums.ExcelTemplate;
import com.xuerhua.yxt.common.enums.Status;
import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.controller.MailboxPrincipalController;
import com.xuerhua.yxt.excel.CellUtil;
import com.xuerhua.yxt.excel.JxlsExcelView;
import com.xuerhua.yxt.page.OrderBy;
import com.xuerhua.yxt.page.Page;
import com.xuerhua.yxt.reqVo.BaseQueryVO;
import com.xuerhua.yxt.reqVo.SchoolPropertyExportQueryVo;
import com.xuerhua.yxt.reqVo.StudentReqVO;
import com.xuerhua.yxt.reqVo.TeacherWorkSignReqVO;
import com.xuerhua.yxt.reqVo.WorkApprovalCountQueryVO;
import com.xuerhua.yxt.service.IFinalTermScoreReportService;
import com.xuerhua.yxt.service.IParentService;
import com.xuerhua.yxt.service.IPrincipalMailboxService;
import com.xuerhua.yxt.service.ISchoolPropertyService;
import com.xuerhua.yxt.service.IStudentService;
import com.xuerhua.yxt.service.ITeacherChangeCourseApplyService;
import com.xuerhua.yxt.service.ITeacherLeaveService;
import com.xuerhua.yxt.service.ITeacherService;
import com.xuerhua.yxt.service.ITeacherWorkSignService;
import com.xuerhua.yxt.service.IWorkApprovalService;
import com.xuerhua.yxt.utils.BeanUtils;
import com.xuerhua.yxt.utils.DateUtil;
import com.xuerhua.yxt.utils.ExcelExportUtil;
import com.xuerhua.yxt.utils.ExportSetInfoUtil;
import com.xuerhua.yxt.utils.StringUtil;
import com.xuerhua.yxt.utils.ValidatorUtil;
import com.xuerhua.yxt.vo.PrincipalMailboxQueryVO;
import com.xuerhua.yxt.vo.StudentValidtorVO;
import com.xuerhua.yxt.vo.TeacherChangeCourseApplyQueryVO;
import com.xuerhua.yxt.vo.TeacherLeaveQueryVO;
import com.xuerhua.yxt.vo.TeacherValidtorVO;
import com.xuerhua.yxt.vo.WorkApprovalQueryVO;
import com.xuerhua.yxt.wechat.utils.WechatGlobalMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 报表
 */
@RequestMapping("sys/report")
@Controller
public class ReportController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(MailboxPrincipalController.class);
    @Autowired
    private IPrincipalMailboxService principalMailboxService;
    @Autowired
    private IWorkApprovalService workApprovalService;
    @Autowired
    private ITeacherLeaveService teacherLeaveService;
    @Autowired
    private ITeacherChangeCourseApplyService teacherChangeCourseApplyService;
    @Autowired
    private ISchoolPropertyService schoolPropertyService;
    @Autowired
    private IParentService parentService;
    @Autowired
    private IStudentService studentService;
    @Autowired
    private ITeacherService teacherService;
    @Autowired
    private IFinalTermScoreReportService finalTermScoreReportService;
    @Autowired
    private ITeacherWorkSignService teacherWorkSignService;

    /**
     * 校产库存报表
     */
    @RequestMapping("schoolPropertyStock")
    public String schoolPropertyStock() {
        return "sys/schoolPropertyStock";
    }

    /**
     * 校产入库记录
     */
    @RequestMapping("schoolPropertyInput")
    public String schoolPropertyInput() {
        return "sys/schoolPropertyInput";
    }

    /**
     * 校产消耗品领用
     */
    @RequestMapping("schoolPropertyConsumablesApply")
    public String schoolPropertyConsumablesApply() {
        return "sys/schoolPropertyConsumablesApply";
    }

    /**
     * 校产非消耗品借还
     */
    @RequestMapping("schoolPropertyLendAndReturn")
    public String schoolPropertyLendAndReturn() {
        return "sys/schoolPropertyLendAndReturn";
    }

    /**
     * 校长信箱
     */
    @RequestMapping("headmaster")
    public String headmasterIndex() {
        return "sys/headmaster";
    }

    /**
     * 加班申请审批
     */
    @RequestMapping("overtimeApply")
    public String overtimeApplyIndex() {
        return "sys/overtimeApplyIndex";
    }

    /**
     * 打印纸申请审批
     */
    @RequestMapping("printingPaper")
    public String printingPaperIndex() {
        return "sys/printingPaperIndex";
    }

    /**
     * 校车审批
     */
    @RequestMapping("schoolBus")
    public String schoolBusIndex() {
        return "sys/schoolBusIndex";
    }

    /**
     * 教学用品申请审批
     */
    @RequestMapping("teachingGoods")
    public String teachingGoodsIndex() {
        return "sys/teachingGoodsIndex";
    }

    /**
     * 复印油纸审批
     */
    @RequestMapping("copyPaper")
    public String copyPaperIndex() {
        return "sys/copyPaperIndex";
    }

    /**
     * @return
     */
    @RequestMapping("teacherLeave")
    public String teacherLeave() {
        return "sys/teacherLeave";
    }

    /**
     * 代看课报表
     *
     * @return
     */
    @RequestMapping("teacherReplaceCourse")
    public String teacherReplaceCourse() {
        return "sys/teacherReplaceCourse";
    }

    /**
     * 调课报表
     *
     * @return
     */
    @RequestMapping("teacherChangeCourse")
    public String teacherChangeCourse() {
        return "sys/teacherChangeCourse";
    }

    /**
     * 校产报表
     */
    @RequestMapping(value = "schoolProperty/{type}")
    @ResponseBody
    public Grid schoolProperty(@PathVariable("type") String type, SchoolPropertyExportQueryVo vo) {
        try {
            Grid grid = new Grid();
            switch (type) {
                //库存管理
                case "stock":
                    if (vo.getCycleUse() != null && vo.getCycleUse() == -1)
                        vo.setCycleUse(null);
                    if (vo.getTypeId() != null && vo.getTypeId() == -1)
                        vo.setTypeId(null);
                    Page<SchoolPropertyStockExportView> page = new Page<>();
                    List<OrderBy> sorts = new ArrayList<>();
                    sorts.add(new OrderBy("cycleUse", "desc"));
                    sorts.add(new OrderBy("ID", "desc"));

                    page.setSorts(sorts);
                    page.setParams(vo);
                    List<SchoolPropertyStockExportView> list = schoolPropertyService.selectAllStockForExportToExcelByPage(page);
                    grid.setTotal(page.getTotalRecord());
                    grid.setRows(list);
                    break;
                //入库管理
                case "inputRecord":
                    if (vo.getStartTimeText() != null && vo.getStartTimeText() != "")
                        vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));

                    if (vo.getEndTimeText() != null && vo.getEndTimeText() != "")
                        vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));

                    Page<SchoolPropertyInputExportView> input = new Page<>();
                    List<OrderBy> isorts = new ArrayList<>();
                    isorts.add(new OrderBy("createTime", "desc"));
                    input.setSorts(isorts);
                    input.setParams(vo);
                    List<SchoolPropertyInputExportView> inputList = schoolPropertyService.
                            selectSchoolPropertyInputForExportToExcelByPage(input);
                    grid.setTotal(input.getTotalRecord());
                    grid.setRows(inputList);
                    break;
                //消耗品领用
                case "consumablesApply": {
                    if (vo.getStartTimeText() != null && vo.getStartTimeText() != "")
                        vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));

                    if (vo.getEndTimeText() != null && vo.getEndTimeText() != "")
                        vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));

                    Page<SchoolPropertyConsumablesApplyExportView> ca = new Page<>();
                    List<OrderBy> csorts = new ArrayList<>();
                    csorts.add(new OrderBy("createTime", "DESC"));
                    ca.setSorts(csorts);
                    ca.setParams(vo);
                    List<SchoolPropertyConsumablesApplyExportView> clist = schoolPropertyService.
                            selectSchoolPropertyConsumablesApplyForExportToExcelByPage(ca);
                    grid.setTotal(ca.getTotalRecord());
                    grid.setRows(clist);
                    break;
                }
                //非消耗品借还
                case "lendAndReturn": {
                    if (vo.getStartTimeText() != null && vo.getStartTimeText() != "")
                        vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));

                    if (vo.getEndTimeText() != null && vo.getEndTimeText() != "")
                        vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));

                    Page<SchoolPropertyLendAndReturnExportView> lrpage = new Page<>();
                    List<OrderBy> lrsorts = new ArrayList<>();
                    lrsorts.add(new OrderBy("state", "ASC"));
                    lrsorts.add(new OrderBy("createTime", "DESC"));
                    lrsorts.add(new OrderBy("updateTime", "DESC"));
                    lrpage.setSorts(lrsorts);
                    lrpage.setParams(vo);
                    List<SchoolPropertyLendAndReturnExportView> lrList = schoolPropertyService.
                            selectSchoolPropertyLendAndReturnForExportToExcelByPage(lrpage);
                    grid.setTotal(lrpage.getTotalRecord());
                    grid.setRows(lrList);
                    break;
                }
                default:
                    break;
            }
            return grid;
        } catch (Exception e) {
            logger.error("schoolPropertyReport error ", e);
            return new Grid();
        }
    }

    /**
     * 校产报表导出
     */
    @RequestMapping(value = "schoolProperty/export/{type}")
    public ModelAndView schoolPropertyReport(@PathVariable("type") String type, SchoolPropertyExportQueryVo vo, ModelAndView mv) {
        try {
            if (vo.getStartTimeText() != null && vo.getStartTimeText() != "")
                vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));

            if (vo.getEndTimeText() != null && vo.getEndTimeText() != "")
                vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));
            JxlsExcelView view = new JxlsExcelView();

            switch (type) {
                //库存管理
                case "stock":
                    if (vo.getCycleUse() != null && vo.getCycleUse() == -1)
                        vo.setCycleUse(null);
                    if (vo.getTypeId() != null && vo.getTypeId() == -1)
                        vo.setTypeId(null);

                    List<SchoolPropertyStockExportView> list = schoolPropertyService.selectAllStockForExportToExcelByParams(vo);
                    view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_STOCK.getUrl());
                    view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_STOCK.getName());
                    mv.addObject("list", list);
                    break;
                //入库管理
                case "inputRecord":

                    List<SchoolPropertyInputExportView> inputList = schoolPropertyService.selectSchoolPropertyInputForExportToExcelByParams(vo);
                    view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_INPUTRECORD.getUrl());
                    view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_INPUTRECORD.getName());
                    mv.addObject("list", inputList);
                    break;
                //消耗品领用
                case "consumablesApply": {

                    List<SchoolPropertyConsumablesApplyExportView> clist = schoolPropertyService.
                            selectSchoolPropertyConsumablesApplyForExportToExcelByParams(vo);
                    view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_CONSUMABLESAPPLY.getUrl());
                    view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_CONSUMABLESAPPLY.getName());
                    mv.addObject("list", clist);
                    break;
                }
                //非消耗品借还
                case "lendAndReturn": {

                    List<SchoolPropertyLendAndReturnExportView> lrList = schoolPropertyService.
                            selectSchoolPropertyLendAndReturnForExportToExcelByParams(vo);
                    view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_LENDANDRETURN.getUrl());
                    view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_LENDANDRETURN.getName());
                    mv.addObject("list", lrList);
                    break;
                }
                default:
                    break;
            }

            mv.setView(view);
            return mv;
        } catch (Exception e) {
            logger.error("schoolPropertyReport error ", e);
            return mv;
        }
    }

    @RequestMapping("teacherLeave/page")
    @ResponseBody
    Object teacherLeavePage(TeacherLeaveQueryVO vo) {
        try {
            Page<TeacherLeaveView> page = new Page<>();
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("UPDATE_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<TeacherLeaveView> list = teacherLeaveService.selectListByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("---teacherLeavePage error={}", e);
        }
        return null;
    }

    @RequestMapping("teacherLeave/export")
    ModelAndView teacherLeaveExport(ModelAndView modelAndView, TeacherLeaveQueryVO vo) {
        try {
            Page<TeacherLeaveView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("UPDATE_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);
            List<TeacherLeaveView> list = teacherLeaveService.selectListByPage(page);

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHER_LEAVE);
            modelAndView.setView(view);
            modelAndView.getModelMap().put("list", list);
        } catch (Exception e) {
            logger.error("--teacherLeaveExport error ", e);
        }
        return modelAndView;
    }

    @RequestMapping("teacherChangeCourse/page")
    @ResponseBody
    Object teacherChangeCoursePage(TeacherChangeCourseApplyQueryVO vo) {
        try {
            Page<TeacherExchangeCourseApplyItemView> page = new Page<>();
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("UPDATE_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<TeacherExchangeCourseApplyItemView> list = teacherChangeCourseApplyService.selectReportListByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("---teacherChangeCoursePage error={}", e);
        }
        return null;
    }

    @RequestMapping("teacherChangeCourse/export")
    ModelAndView teacherChangeCourseExport(ModelAndView modelAndView, TeacherChangeCourseApplyQueryVO vo) {
        try {
            Page<TeacherExchangeCourseApplyItemView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("UPDATE_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);
            List<TeacherExchangeCourseApplyItemView> list = teacherChangeCourseApplyService.selectReportListByPage(page);
            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHER_CHANGE_COURSE);
            modelAndView.setView(view);
            modelAndView.getModelMap().put("list", list);
        } catch (Exception e) {
            logger.error("--teacherChangeCourseExport error ", e);
        }
        return modelAndView;
    }

    /**
     * 校长信箱查询
     */
    @RequestMapping(value = {"headmaster/list"})
    @ResponseBody
    Object principalMailboxQuery(PrincipalMailboxQueryVO vo) {
        try {
            Page<PrincipalMailboxView> page = new Page<>();
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("REPLY_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            if (vo.getIsReply() != null && vo.getIsReply() == 10)
                vo.setIsReply(null);
            if (vo.getSendTimeQuery() != null)
                vo.setSendTime(DateUtil.strToDate(vo.getSendTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
            if (vo.getReplyTimeQuery() != null)
                vo.setReplyTime(DateUtil.strToDate(vo.getReplyTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));

            List<PrincipalMailboxView> list = principalMailboxService.selectListByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("---principalMailboxQuery error={}", e);
        }
        return null;
    }

    @RequestMapping(value = {"headmaster/export"})
    ModelAndView principalMailboxExport(ModelAndView modelAndView, PrincipalMailboxQueryVO vo) {
        try {

            Page<PrincipalMailboxView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("CREATE_TIME", "desc"));
            sorts.add(new OrderBy("REPLY_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.HEADEMASTER_MAILBOX);
            modelAndView.setView(view);

            if (vo.getIsReply() != null && vo.getIsReply() == 10)
                vo.setIsReply(null);

            if (vo.getSendTimeQuery() != null)
                vo.setSendTime(DateUtil.strToDate(vo.getSendTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
            if (vo.getReplyTimeQuery() != null)
                vo.setReplyTime(DateUtil.strToDate(vo.getReplyTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));

            List<PrincipalMailboxView> list = principalMailboxService.selectListByPage(page);
            modelAndView.getModelMap().put("list", list);
        } catch (Exception e) {
            logger.error("principalMailboxExport error ", e);
        }
        return modelAndView;
    }

    /**
     * 加班申请审批
     *
     * @param vo
     * @return
     */
    @RequestMapping("overtimeApply/list")
    @ResponseBody
    Grid overtimeApplyPageQuery(WorkApprovalQueryVO vo) {
        try {
            valid(vo);
            Page<OvertimeApplyView> page = new Page<OvertimeApplyView>();
            vo.setApprovalType("overtimeApply");
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("APPLY_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());

            List<OvertimeApplyView> list = workApprovalService.selectWorkApprovalOfOvertimeApplyByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("--overtimeApplyPageQuery error={}", e);
        }
        return new Grid();
    }

    /**
     * 加班申请审批导出excel
     */
    @RequestMapping(value = "overtimeApply/export")
    public ModelAndView overtimeApplyExportToExcel(ModelAndView modelAndView, WorkApprovalQueryVO vo) {
        try {

            valid(vo);
            WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
            countVo.setApprovalType("overtimeApply");
            Integer size = workApprovalService.countAllRecord(countVo);
            vo.setRows(size + 1);

            Grid schoolBusPageQuery = overtimeApplyPageQuery(vo);

            modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.OVERTIME_APPLY);

            modelAndView.setView(view);
        } catch (Exception e) {
            logger.error("--overtimeApplyExportToExcel error={}", e);
        }
        return modelAndView;
    }

    /**
     * 校车审批查询
     *
     * @param vo
     * @return
     */
    @RequestMapping("schoolBus/list")
    @ResponseBody
    Grid schoolBusPageQuery(WorkApprovalQueryVO vo) {
        try {
            valid(vo);
            Page<SchoolBusApprovalView> page = new Page<SchoolBusApprovalView>();
            vo.setApprovalType("schoolBus");
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("APPLY_TIME", "desc"));
            sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<SchoolBusApprovalView> list = workApprovalService.selectWorkApprovalOfSchoolbusByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("--schoolBusPageQuery error={}", e);
        }
        return new Grid();
    }

    /**
     * 校车审批导出excel表
     */
    @RequestMapping(value = "schoolBus/export")
    public ModelAndView schoolBusExportToExcel(ModelAndView modelAndView, WorkApprovalQueryVO vo) {
        try {

            valid(vo);
            WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
            countVo.setApprovalType("schoolBus");
            Integer size = workApprovalService.countAllRecord(countVo);

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.SCHOOL_BUS);
            modelAndView.setView(view);

            vo.setRows(size + 1);
            Grid schoolBusPageQuery = schoolBusPageQuery(vo);
            modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());

        } catch (Exception e) {
            logger.error("--schoolBusExportToExcel error={}", e);
        }
        return modelAndView;
    }


    /**
     * 教学用品申请审批查询
     */
    @RequestMapping("teachingGoods/list")
    @ResponseBody
    Grid teachingGoodsPageQuery(WorkApprovalQueryVO vo) {
        try {

            valid(vo);
            Page<teachingGoodsApprovalView> page = new Page<>();
            vo.setApprovalType("teachingGoods");
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("APPLY_TIME", "desc"));
            sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<teachingGoodsApprovalView> list = workApprovalService.selectWorkApprovalOfTeachingGoodsByPage(page);

            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("--teachingGoodsPageQuery error={}", e);
        }
        return new Grid();
    }

    /**
     * 教学用品审批导出excel表
     */
    @RequestMapping(value = "teachingGoods/export")
    public ModelAndView teachingGoodsExportToExcel(ModelAndView modelAndView, WorkApprovalQueryVO vo) {
        try {
            valid(vo);
            WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
            countVo.setApprovalType("teachingGoods");
            Integer size = workApprovalService.countAllRecord(countVo);

            vo.setRows(size + 1);
            Grid grid = teachingGoodsPageQuery(vo);

            modelAndView.getModelMap().addAttribute("list", grid.getRows());

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHING_GOODS);

            modelAndView.setView(view);
        } catch (Exception e) {
            logger.error("--teachingGoodsExportToExcel error={}", e);
        }
        return modelAndView;
    }

    /**
     * 复印油纸审批查询
     */
    @RequestMapping("copyPaper/list")
    @ResponseBody
    Grid copyPaperPageQuery(WorkApprovalQueryVO vo) {
        try {
            valid(vo);
            Page<CopyPaperApprovalView> page = new Page<CopyPaperApprovalView>();
            vo.setApprovalType("copyPaper");
            Grid grid = new Grid();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("APPLY_TIME", "desc"));
            sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<CopyPaperApprovalView> list = workApprovalService.selectWorkApprovalOfCopyPaperByPage(page);
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("--copyPaperPageQuery error={}", e);
        }
        return new Grid();
    }


    /**
     * 复印油纸审批导出excel
     */
    @RequestMapping(value = "copyPaper/export")
    public ModelAndView copyPaperExportToExcel(ModelAndView modelAndView, WorkApprovalQueryVO vo) {
        try {

            valid(vo);
            WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
            countVo.setApprovalType("copyPaper");
            Integer size = workApprovalService.countAllRecord(countVo);
            System.out.println("----------------------------------------------------------- = " + size);
            vo.setRows(size + 1);
            Grid schoolBusPageQuery = copyPaperPageQuery(vo);

            modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.COPY_PAPER);

            modelAndView.setView(view);
        } catch (Exception e) {
            logger.error("--copyPaperExportToExcel error={}", e);
        }
        return modelAndView;
    }

    /**
     * 打印纸申请审批
     * PrintingPaperApprovalView
     */
    @RequestMapping("printingPaper/list")
    @ResponseBody
    Grid printingPaperApprovalPageQuery(WorkApprovalQueryVO vo) {
        try {
            valid(vo);

            vo.setApprovalType("printingPaper");

            Page<PrintingPaperApprovalView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("APPLY_TIME", "desc"));
            sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(vo.getRows());
            List<PrintingPaperApprovalView> list = workApprovalService.selectWorkApprovalOfPrintingPaperByPage(page);
            Grid grid = new Grid();
            grid.setRows(list);
            grid.setTotal(page.getTotalRecord());
            return grid;
        } catch (Exception e) {
            logger.error("--printingPaperApprovalPageQuery error={}", e);
        }
        return new Grid();
    }

    /**
     * 打印纸申请审批导出excel
     */
    @RequestMapping(value = "printingPaper/export")
    public ModelAndView printingPaperExportToExcel(ModelAndView modelAndView, WorkApprovalQueryVO vo) {
        try {

            valid(vo);
            WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
            countVo.setApprovalType("printingPaper");
            Integer size = workApprovalService.countAllRecord(countVo);

            vo.setRows(size + 1);
            Grid schoolBusPageQuery = printingPaperApprovalPageQuery(vo);

            modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.PRINTING_PAPER);

            modelAndView.setView(view);
        } catch (Exception e) {
            logger.error("--printingPaperExportToExcel error={}", e);
        }
        return modelAndView;
    }

    private void valid(WorkApprovalQueryVO vo) {
        if ("111".equals(vo.getApprovalStatus()))
            vo.setApprovalStatus(null);
        if (vo.getApplyTimeQuery() != null) {
            vo.setApplyTime(DateUtil.strToDate(vo.getApplyTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
        }
        if (vo.getApprovalTimeQuery() != null) {
            vo.setApprovalTime(DateUtil.strToDate(vo.getApprovalTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
        }
    }


    @RequestMapping("studentForHkExport")
    ModelAndView studentForHkExport(ModelAndView modelAndView, StudentReqVO vo) {
        try {

            Page<StudentPersonImportView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("grade"));
            sorts.add(new OrderBy("clazz"));
            sorts.add(new OrderBy("学号"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.STUDENT_PERSON_IMPORT);
            modelAndView.setView(view);

            List<StudentPersonImportView> list = studentService.selectPersonImport(page);
            modelAndView.getModelMap().put("list", list);

        } catch (Exception e) {
            logger.error("studentExport error ", e);
        }
        return modelAndView;
    }

    @RequestMapping("parentForHkExport")
    ModelAndView parentForHkExport(ModelAndView modelAndView, StudentReqVO vo) {
        try {
            Page<ParentPersonImportView> page = new Page<>();
            List<OrderBy> sorts = new ArrayList<>();
            sorts.add(new OrderBy("grade"));
            sorts.add(new OrderBy("clazz"));
            page.setSorts(sorts);
            page.setParams(vo);
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);

            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.PARENT_PERSON_IMPORT);
            modelAndView.setView(view);

            List<ParentPersonImportView> list = parentService.selectPersonImport(page);
            modelAndView.getModelMap().put("list", list);
        } catch (Exception e) {
            logger.error("parentExport error ", e);
        }
        return modelAndView;
    }

    /**
     * 期末成绩报告模板
     */
    @RequestMapping(value = "finalTermScoreReportTemplate/export")
    public ModelAndView finalTermScoreReportTemplate(ModelAndView modelAndView, BaseQueryVO vo) {
        try {
            StudentReqVO record = new StudentReqVO();
            record.setGrade(vo.getGrade());
            record.setClazz(vo.getClazz());
            record.setSchoolId(vo.getSchoolId());
            List<StudentInfo> list = studentService.selectListByParam(record);
            modelAndView.getModelMap().addAttribute("list", list);

//            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.FINAL_TERM_SCORE_REPORT);
            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.BACKUP_FINAL_TERM_SCORE_REPORT);

            modelAndView.setView(view);
        } catch (Exception e) {
            logger.error("--finalTermScoreReportTemplate error={}", e);
        }
        return modelAndView;
    }

    //上传期末成绩模版
    @RequestMapping("classTermReport/import")
    @ResponseBody
    Object namelistImport(
            @RequestParam(value = "files") MultipartFile buildInfo, BaseQueryVO vo) {
        try {
            if (vo.getTermId() == null) {
                return new RspResult(Status.FAIL.getCode(), "学期不能为空");
            } else if (vo.getGrade() == null) {
                return new RspResult(Status.FAIL.getCode(), "年级不能为空");
            } else if (vo.getClazz() == null) {
                return new RspResult(Status.FAIL.getCode(), "班级不能为空");
            }
            return saveClassTermReportBuildInfo(buildInfo, vo);
        } catch (Exception e) {
            logger.error("--namelistImport, error={}", e);
        }
        return new RspResult(Status.TEMPLATE_ERROR);
    }

    //提交Excel
    public RspResult saveClassTermReportBuildInfo(MultipartFile buildInfo, BaseQueryVO vo) throws Exception {
        // 创建一个FileInputStream 文件输入流
        InputStream inputStream = buildInfo.getInputStream();
        // 创建对Excel工作簿文件的引用
        Workbook wookbook = null;
        String filename = buildInfo.getOriginalFilename();
        String fileType = filename.substring(filename.lastIndexOf(".") + 1,
                filename.length());
        if (fileType.equals("xls")) {
            try {
                wookbook = new HSSFWorkbook(inputStream);
            } catch (Exception e) {
                wookbook = null;
                wookbook = new XSSFWorkbook(inputStream);
            }
        } else {
            wookbook = new XSSFWorkbook(inputStream);
        }
        // 在Excel文档中，第一张工作表的缺省索引是0
        Sheet sheet = wookbook.getSheetAt(0);
        int coloumNum = sheet.getRow(0).getPhysicalNumberOfCells();// 获取总列数
        int rowNum = sheet.getPhysicalNumberOfRows();//获得总行数
        if (rowNum <= 1) {
            return new RspResult(Status.TEMPLATE_DATA_NULL);
        }
        Map<Integer, String> map = new HashMap<>();
        Row headRow = sheet.getRow(0);
        for (int i = 0; i < coloumNum; i++) {
            Cell cell = headRow.getCell((short) i);
            String val = CellUtil.getCellValue(cell);
            if (StringUtils.isNotBlank(val)) {
                map.put(i, StringUtil.removeSpecialChar(val));
            }
        }
        List<FinalTermScoreReportView> list = new ArrayList<>();
        // 遍历行 从第三行开始遍历
        for (int i = 1; i < rowNum; i++) {
            // 读取左上端单元格
            Row row = sheet.getRow(i);
            // 行不为空
            if (row != null) {
                FinalTermScoreReportView scoreReport = new FinalTermScoreReportView();
                for (int j = 0; j < coloumNum; j++) {
                    Cell cell = row.getCell((short) j);
                    if (cell != null) {
                        String val = null;
                        try {
                            val = CellUtil.getCellValue(cell);
                        } catch (Exception e) {
                            logger.error("---第" + i + "行的" + (j + 1) + "异常， error={}", e.getMessage());
                        }
                        if (StringUtils.isBlank(val)) {
                            continue;
                        }
                        val = val.trim();   //去掉两端多余空格
                        String name = map.get(j);
                        if ("学号".equals(name)) scoreReport.setStudentNum(Integer.valueOf(val));
                        else if ("姓名".equals(name)) scoreReport.setStudentName(val);
                        else if ("语文基础".equals(name)) scoreReport.setChinese(val);
                        else if ("阅读积累".equals(name)) scoreReport.setRead2(val);
                        else if ("数学".equals(name)) scoreReport.setMath(val);
                        else if ("计算能力".equals(name)) scoreReport.setCalculate(val);
                        else if ("英语PEP".equals(name)) scoreReport.setEnglish(val);
                        else if ("朗文".equals(name)) scoreReport.setLongman(val);
                        else if ("口语".equals(name)) scoreReport.setEnglishLanguage(val);
                        else if ("道德法制".equals(name)) scoreReport.setQuality(val);
                        else if ("体育".equals(name)) scoreReport.setSports(val);
                        else if ("音乐".equals(name)) scoreReport.setMusic(val);
                        else if ("戏剧".equals(name)) scoreReport.setTheatre(val);
                        else if ("美术".equals(name)) scoreReport.setArts(val);
                        else if ("书法".equals(name)) scoreReport.setCalligraphy(val);
                        else if ("科学".equals(name)) scoreReport.setScience(val);
                        else if ("信息".equals(name)) scoreReport.setInfomation(val);
                        else if ("steam".equalsIgnoreCase(name)) scoreReport.setSteam(val);
                        else if ("评优".equals(name)) scoreReport.setAppraising(val);
                        else if ("期末评语".equals(name)) scoreReport.setComment(val);
                        else if ("校内奖项".equals(name)) scoreReport.setSchoolPrize(val);
                    }
                }
                list.add(scoreReport);
            }
        }
        return finalTermScoreReportService.addImportTermScoreReport(list, vo);
    }

    @RequestMapping("student/import")
    @ResponseBody
    Object studentImport(
            @RequestParam(value = "files") MultipartFile buildInfo) {
        try {
            return saveStudentBuildInfo(buildInfo);
        } catch (Exception e) {
            logger.error("--namelistImport, error={}", e);
        }
        return new RspResult(Status.TEMPLATE_ERROR);
    }

    public RspResult saveStudentBuildInfo(MultipartFile buildInfo) throws Exception {
        AdminUser adminUser = getAdminUser();
        // 创建一个FileInputStream 文件输入流
        InputStream inputStream = buildInfo.getInputStream();
        // 创建对Excel工作簿文件的引用
        Workbook wookbook = null;
        String filename = buildInfo.getOriginalFilename();
        String fileType = filename.substring(filename.lastIndexOf(".") + 1,
                filename.length());
        if (fileType.equals("xls")) {
            try {
                wookbook = new HSSFWorkbook(inputStream);
            } catch (Exception e) {
                wookbook = null;
                wookbook = new XSSFWorkbook(inputStream);
            }
        } else {
            wookbook = new XSSFWorkbook(inputStream);
        }
        // 在Excel文档中，第一张工作表的缺省索引是0
        Sheet sheet = wookbook.getSheetAt(0);
        int coloumNum = sheet.getRow(0).getPhysicalNumberOfCells();// 获取总列数
        int rowNum = sheet.getPhysicalNumberOfRows();//获得总行数
        if (rowNum <= 1) {
            return new RspResult(Status.TEMPLATE_DATA_NULL);
        }
        Map<Integer, String> map = new HashMap<>();
        Row headRow = sheet.getRow(2);
        for (int i = 0; i < coloumNum; i++) {
            Cell cell = headRow.getCell((short) i);
            String val = CellUtil.getCellValue(cell);
            if (StringUtils.isNotBlank(val)) {
                map.put(i, StringUtil.removeSpecialChar(val));
            }
        }
        List<StudentValidtorVO> list = new ArrayList<>();
        Map<String, Integer> numMap = new HashMap<>();
        // 遍历行 从第三行开始遍历
        for (int i = 3; i < rowNum; i++) {
            // 读取左上端单元格
            Row row = sheet.getRow(i);
            // 行不为空
            if (row != null) {
                StudentValidtorVO req = new StudentValidtorVO();
                req.setRow(i + 1);
                Integer grade = getCurrentTerm().getTermKey();
                for (int j = 0; j < coloumNum; j++) {
                    Cell cell = row.getCell((short) j);
                    if (cell != null) {
                        String val = null;
                        try {
                            val = CellUtil.getCellValue(cell);
                        } catch (Exception e) {
                            logger.error("---第" + i + "行的" + (j + 1) + "异常， error={}", e.getMessage());
                        }
                        if (StringUtils.isBlank(val)) {
                            continue;
                        }
                        val = val.trim();
                        String name = map.get(j);
                        if ("年级".equals(name)) {
                            if ("一年级".equals(val)) req.setGrade(grade);
                            else if ("二年级".equals(val)) req.setGrade(grade - 1);
                            else if ("三年级".equals(val)) req.setGrade(grade - 2);
                            else if ("四年级".equals(val)) req.setGrade(grade - 3);
                            else if ("五年级".equals(val)) req.setGrade(grade - 4);
                            else if ("六年级".equals(val)) req.setGrade(grade - 5);
                        } else if ("班级".equals(name)) {
                            req.setClazz(Integer.valueOf(val));
                            String key = req.getGrade() + "" + req.getClazz();
                            if (!numMap.containsKey(key)) {
                                numMap.put(key, 1);
                            }
                            int num = numMap.get(key);
                            req.setStudentNum(num);
                            numMap.put(key, num + 1);
                        } else if ("学生姓名".equals(name)) req.setName(val);
                        else if ("学生身份证".equals(name)) req.setIdNo(val);
                        else if ("性别".equals(name)) req.setSex(val);
                        else if ("爸爸姓名".equals(name)) req.setFatherName(val);
                        else if ("爸爸联系电话".equals(name)) req.setFatherMobile(val);
                        else if ("妈妈姓名".equals(name)) req.setMotherName(val);
                        else if ("妈妈联系电话".equals(name)) req.setMotherMobile(val);
                        else if ("家庭住址".equals(name)) req.setHomeAddr(val);
                    }
                }
                req.setSchoolId(adminUser.getTeacherInfo().getSchoolId());
                req.setStudyNo("" + req.getGrade() +
                        (req.getClazz() < 10 ? "0" + req.getClazz() : req.getClass()) +
                        (req.getStudentNum() < 10 ? "0" + req.getStudentNum() : req.getStudentNum()));
                list.add(req);
            }
        }
        List<String> errorList = new ArrayList<>();
        for (StudentValidtorVO vo : list) {
            String validator = ValidatorUtil.validatorParams(vo);
            if (null != validator) {
                errorList.add("第" + vo.getRow() + "行" + validator);
            }
        }
        if (errorList.size() > 0) {
            return new RspResult(Status.FAIL.getCode(), String.join(",", errorList));
        }
        studentService.insertBatch(BeanUtils.copyAs(list, StudentInfo.class));
        return new RspResult(Status.SUCCESS);
    }

    @RequestMapping("teacher/import")
    @ResponseBody
    Object teacherImport(
            @RequestParam(value = "files") MultipartFile buildInfo) {
        try {
            return saveTeacherBuildInfo(buildInfo);
        } catch (Exception e) {
            logger.error("--namelistImport, error={}", e);
        }
        return new RspResult(Status.TEMPLATE_ERROR);
    }

    public RspResult saveTeacherBuildInfo(MultipartFile buildInfo) throws Exception {
        AdminUser adminUser = getAdminUser();
        // 创建一个FileInputStream 文件输入流
        InputStream inputStream = buildInfo.getInputStream();
        // 创建对Excel工作簿文件的引用
        Workbook wookbook = null;
        String filename = buildInfo.getOriginalFilename();
        String fileType = filename.substring(filename.lastIndexOf(".") + 1,
                filename.length());
        if (fileType.equals("xls")) {
            try {
                wookbook = new HSSFWorkbook(inputStream);
            } catch (Exception e) {
                wookbook = null;
                wookbook = new XSSFWorkbook(inputStream);
            }
        } else {
            wookbook = new XSSFWorkbook(inputStream);
        }
        // 在Excel文档中，第一张工作表的缺省索引是0
        Sheet sheet = wookbook.getSheetAt(0);
        int coloumNum = 8;//sheet.getRow(0).getPhysicalNumberOfCells();// 获取总列数
        int rowNum = sheet.getPhysicalNumberOfRows();//获得总行数
        if (rowNum <= 1) {
            return new RspResult(Status.TEMPLATE_DATA_NULL);
        }
        Map<Integer, String> map = new HashMap<>();
        Row headRow = sheet.getRow(2);
        for (int i = 0; i < coloumNum; i++) {
            Cell cell = headRow.getCell((short) i);
            String val = CellUtil.getCellValue(cell);
            if (StringUtils.isNotBlank(val)) {
                map.put(i, StringUtil.removeSpecialChar(val));
            }
        }
        List<TeacherValidtorVO> list = new ArrayList<>();
        // 遍历行 从第三行开始遍历
        for (int i = 3; i < rowNum; i++) {
            // 读取左上端单元格
            Row row = sheet.getRow(i);
            // 行不为空
            if (row != null) {
                TeacherValidtorVO req = new TeacherValidtorVO();
                req.setRow(i + 1);
                Integer grade = getCurrentTerm().getTermKey();
                for (int j = 0; j < coloumNum; j++) {
                    Cell cell = row.getCell((short) j);
                    if (cell != null) {
                        String val = null;
                        try {
                            val = CellUtil.getCellValue(cell);
                        } catch (Exception e) {
                            logger.error("---第" + i + "行的" + (j + 1) + "异常， error={}", e.getMessage());
                        }
                        if (StringUtils.isBlank(val)) {
                            continue;
                        }
                        val = val.trim();
                        String name = map.get(j);
                        if ("任课年级".equals(name)) {
                            if ("一年级".equals(val)) req.setGrade(grade);
                            else if ("二年级".equals(val)) req.setGrade(grade - 1);
                            else if ("三年级".equals(val)) req.setGrade(grade - 2);
                            else if ("四年级".equals(val)) req.setGrade(grade - 3);
                            else if ("五年级".equals(val)) req.setGrade(grade - 4);
                            else if ("六年级".equals(val)) req.setGrade(grade - 5);
                        } else if ("教师姓名".equals(name)) req.setName(val);
                        else if ("身份证号".equals(name)) req.setIdNo(val);
                        else if ("性别".equals(name)) req.setSex(val);
                        else if ("联系号码".equals(name)) req.setMobile(val);
                        else if ("家庭住址".equals(name)) req.setLiveAddr(val);
                        else if ("任教科目".equals(name)) {
                            Map<Integer, String> subjectMap = (Map<Integer, String>) WechatGlobalMap.get(Const.CACHE_SUBJECT).getValue();
                            if (subjectMap.containsValue(val)) {
                                for (Entry<Integer, String> entry : subjectMap.entrySet()) {
                                    if (val.equals(entry.getValue())) {
                                        req.setSubjectId(entry.getKey());
                                        break;
                                    }
                                }
                            }
                        } else if ("职位".equals(name)) {
                            Map<String, OrganizeDepart> odMap = (Map<String, OrganizeDepart>) WechatGlobalMap.get(Const.CACHE_ORGANIZE_DEPART).getValue();
                            String[] strings = val.split("、");
                            List<Integer> postions = new ArrayList<>();
                            List<Integer> departs = new ArrayList<>();
                            for (String str : strings) {
                                for (OrganizeDepart value : odMap.values()) {
                                    if (str.equals(value.getPosition())) {
                                        postions.add(value.getId());
                                        departs.add(value.getParentId());
                                    }
                                }
                            }
                            req.setPosition(StringUtils.join(postions, ","));
                            req.setDepart(StringUtil.delRepeatStr(StringUtils.join(departs, ",")));
                        }
                        /**
                         * @author hhk
                         * 参数是可以获取到的
                         */
                        req.setSchoolId(adminUser.getTeacherInfo().getSchoolId());
                    }
                }
                list.add(req);
            }
        }
        List<String> errorList = new ArrayList<>();
        for (TeacherValidtorVO vo : list) {
            String validator = ValidatorUtil.validatorParams(vo);
            if (null != validator) {
                errorList.add("第" + vo.getRow() + "行" + validator);
            }
        }
        if (errorList.size() > 0) {
            return new RspResult(Status.FAIL.getCode(), String.join(",", errorList));
        }
        teacherService.insertBatch(BeanUtils.copyAs(list, TeacherInfo.class));
        return new RspResult(Status.SUCCESS);
    }


    @RequestMapping("teacherWorkSign/export")
    ModelAndView workSignExport(TeacherWorkSignReqVO vo) {
        ModelAndView modelAndView = new ModelAndView();
        try {
            Page<TeacherWorkSign> page = new Page<>();
            page.setPageNo(vo.getPage());
            page.setPageSize(Integer.MAX_VALUE - 1);
            page.setParams(vo);
            List<TeacherWorkSign> list = teacherWorkSignService.selectListByPage(page);
            //数据源
            LinkedHashMap<String, List> map = new LinkedHashMap<String, List>();
            String title = "教师上班签到记录";
            map.put(title, list);

            //标题  和  标题变量
            List<String[]> headNames = new ArrayList<String[]>();
            headNames.add(new String[]{"教师姓名", "日期", "签到主题", "签到时间"});
            List<String[]> fieldNames = new ArrayList<String[]>();
            fieldNames.add(new String[]{"teacherName", "signDate", "signTopic", "signTimeText"});

            //excel生成帮助类
            List<Integer[]> columnFormat = new ArrayList<Integer[]>();
            Integer[] format = new Integer[22];
            columnFormat.add(format);

            String[] titles = new String[]{title};
            //excel生成帮助类
            ExportSetInfoUtil setInfo = new ExportSetInfoUtil(map, titles, headNames, fieldNames, columnFormat);
            request.setAttribute("exportDatas", setInfo);

            //生成
            modelAndView = new ModelAndView(new ExcelExportUtil(title + ".xls", ""));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return modelAndView;
    }


    /**
     * @author huhekun
     * @date 2019/12/31
     * @descriptioin 将学生期末报告单导出的Controller
     */
    @RequestMapping(value = "studentFianlTermScoreReport/export", method = RequestMethod.GET)
    public ModelAndView exportStudentFianlTermScoreReportExcel(ModelAndView mdv, BaseQueryVO vo) {
        try {
            StudentReqVO record = new StudentReqVO();
            record.setGrade(vo.getGrade());
            record.setClazz(vo.getClazz());
            record.setSchoolId(vo.getSchoolId());
            record.setTermId(vo.getTermId());
            List<StudentInfoAndScore> sias = finalTermScoreReportService.selectInfoByTermidAndGradeAndClazz(record);
            mdv.getModelMap().addAttribute("list", sias);
            JxlsExcelView view = new JxlsExcelView(ExcelTemplate.STUDENT_TERM_GRADE_REPORT);
            mdv.setView(view);
        } catch (Exception e) {
            logger.error("--finalTermScoreReportTemplate error={}", e);
        }
        return mdv;
    }
}

